package com.tanhua.dubbo.api;

import com.tanhua.dubbo.api.mongo.VideoApi;
import com.tanhua.dubbo.utils.IdWorker;
import com.tanhua.model.mongo.Video;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;

@DubboService
public class VideoApiImpl implements VideoApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Autowired
    private IdWorker idWorker;

    /**
     * 发布小视频
     *
     * @param pojo
     */
    @Override
    public void add(Video pojo) {
        // idWorker.getNextId("video")中参数video不能修改，给推荐系统使用
        pojo.setVid(idWorker.getNextId("video"));
        pojo.setCreated(System.currentTimeMillis());
        mongoTemplate.insert(pojo);
    }
}
